package proxirabais.mobile.activity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import proxirabais.mobile.R;
import proxirabais.mobile.R.id;
import proxirabais.mobile.R.layout;

import messages.SystemMessage;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import data.Config;
import data.Promotion;
import data.json.JsonParserPromotion;

public class ShowMarkerActivity extends Activity{

	
	

	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);

		setContentView(R.layout.showusermarker);

		Bundle extras = getIntent().getExtras();
        int id = Integer.parseInt(extras.getString(SystemMessage.PROMOTION_ID));
        Promotion p = null;
        
        String strUrl  =("http://"+Config.host+"/proxirabaisServer/PromotionServlet?"+SystemMessage.ACTION+"="+SystemMessage.GET_USER_PROMOTION+"&"+SystemMessage.PROMOTION_ID+"="+id);
        
        
        
        try {

			URL url = new URL(strUrl);

			// Read all the text returned by the server
			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));			
			String str;
			if ((str = in.readLine()) != null) {
				JsonParserPromotion jsonProm = new JsonParserPromotion();
				p = jsonProm.jsonRead(str);				
			}			
			in.close();
		} catch (MalformedURLException e) {
			Log.v("ERROR",e.getMessage());
		} catch (IOException e) {
			Log.v("ERROR",e.getMessage());
		}
		
		
		
		//afficher les info
		if (p != null)
		{
			TextView nom = (TextView)findViewById(R.id.idTitreShowMarker);
			nom.setText(p.getNom());
			
			TextView desc = (TextView)findViewById(R.id.idDescShowMarker);
			desc.setText(p.getDescription());
		}
		
	

	}
	
}
